﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Sunyi.Project.WebPoint.BusinessLogic;
using Sunyi.Project.WebPoint.Common;
using Sunyi.Project.WebPoint.WebControl;

namespace ActivitySystem.Web.Activity
{
    public partial class UserSearch : WebPointPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.Params[WebPointGlobalConstant.UserName]))
            {
                string userName = Request.Params[WebPointGlobalConstant.UserName].Trim();
                if (userName.Length < 2)
                {
                    Response.Write("[]");
                }
                else
                {
                    UserManager userManager = new UserManager();
                    var users = userManager.Search(userName, string.Empty, true, 0, int.MaxValue);
                    StringBuilder sbUsersJson = new StringBuilder();
                    sbUsersJson.Append("[");
                    foreach (var user in users)
                    {
                        sbUsersJson.Append("\"");
                        sbUsersJson.Append(user.UserName);
                        sbUsersJson.Append("\"");
                        sbUsersJson.Append(WebPointGlobalConstant.Comma);
                    }
                    sbUsersJson.Remove(sbUsersJson.Length - 1, 1);
                    sbUsersJson.Append("]");

                    string usersJson = sbUsersJson.ToString();

                    Response.Write(usersJson);
                }
                Response.Flush();
            }
        }
    }
}